home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
PowerMacOberon 1.2
/
Dialogs
/
DialogDates.Mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1995-06-30
|
5KB
|
147 lines
Syntax10.Scn.Fnt
Syntax10i.Scn.Fnt
StampElems
Alloc
16 Dec 94
Syntax10b.Scn.Fnt
MODULE DialogDates;
(** Markus Knasm
ller 12 Sep 94 -
(* This sourcecode uses parts of ClockElems - gri 18.3.91 & StampElems - CAS 26.6.92 *)
IMPORT DialogFrames, Dialogs, DialogTexts, Oberon, Display, Fonts, GraphicUtils, In, Input, TextFrames, Texts, Viewers;
CONST
W* = 60; H* = 20; MM = 1;
ticks = 300; (* Oberon.Time ticks per second*)
TYPE
Item* = POINTER TO ItemDesc;
ItemDesc* = RECORD(Dialogs.ObjectDesc)
END;
Time = RECORD timeStamp, dateStamp: LONGINT END;
NotifyMsg = RECORD(Display.FrameMsg) new: Time END;
wakeUp: LONGINT; (* overflow in 82.8 days *)
old: Time; (* displayed Time *)
fnt: Fonts.Font;
Task: Oberon.Task;
month: ARRAY 12*3+1 OF CHAR;
PROCEDURE Format (date: LONGINT; VAR s: ARRAY OF CHAR);
VAR i: INTEGER;
PROCEDURE Pair (x: LONGINT);
BEGIN
IF x >= 10 THEN s[i] := CHR(x DIV 10 + 30H); INC(i) END;
s[i] := CHR(x MOD 10 + 30H); INC(i)
END Pair;
PROCEDURE Label (m: LONGINT);
BEGIN
m := (m-1)*3;
s[i] := month[m]; s[i+1] := month[m+1]; s[i+2] := month[m+2]; INC(i, 3)
END Label;
BEGIN
i := 0;
Pair(date MOD 32); s[i] := " "; INC(i);
Label(date DIV 32 MOD 16); s[i] := " "; INC(i);
Pair(date DIV 512 MOD 128); s[i] := 0X
END Format;
PROCEDURE (c: Item) Draw* (x, y: INTEGER; f: Display.Frame);
(** displays the object at (x, y) in frame f *)
VAR mode, w, h, ox, oy, cx, yh: INTEGER; str: ARRAY 12 OF CHAR; time: Time;
BEGIN
c.GetDim (ox, oy, w, h);
IF c.selected THEN mode := Display.invert ELSE mode := Display.paint END;
yh := y + (h DIV 2) - ((fnt.minY + fnt.maxY) DIV 2);
Oberon.GetClock (time.timeStamp, time.dateStamp);
Format (time.dateStamp, str);
IF h - (yh - y) > fnt.maxY THEN
GraphicUtils.DrawString (f, str, x + 3, yh, w - 4, fnt, mode, GraphicUtils.center, cx)
END
END Draw;
PROCEDURE (c: Item) Print* (x, y: INTEGER);
(** prints the object at printer coordinates (x, y) *)
VAR w, h, ox, oy, yh: INTEGER; fnth: LONGINT; time: Time; str: ARRAY 12 OF CHAR;
BEGIN
c.GetPDim (ox, oy, w, h);
fnth := ((fnt.maxY - fnt.minY) * Dialogs.dUnit) DIV Dialogs.pUnit DIV 2;
yh := y + (h DIV 2) - SHORT (fnth);
Oberon.GetClock (time.timeStamp, time.dateStamp);
Format (time.dateStamp,str);
IF h - (yh - y) > ((fnt.maxY * SHORT (Dialogs.dUnit)) DIV Dialogs.pUnit) THEN
GraphicUtils.PrintString (str, x + 3, yh, w- 4, fnt, GraphicUtils.center, ox)
END
END Print;
PROCEDURE (c: Item) Copy* (VAR dup: Dialogs.Object);
(** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
VAR x: Item;
BEGIN
IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END;
c.Copy^ (dup);
END Copy;
PROCEDURE (c: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel);
VAR keysum: SET; t: Texts.Text;
BEGIN
IF keys = {MM} THEN
keysum := keys;
REPEAT
Input.Mouse(keys, x, y); keysum := keysum + keys;
Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
UNTIL keys = {};
IF (keysum = {MM}) & (c.cmd[0] # 0X) THEN
DialogTexts.GetParText (c.par, c.panel, t);
c.CallCmd (f, Viewers.This (x, y), t)
END
ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
END
END Track;
PROCEDURE (c: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
(** handles messages which were sent to frame f *)
BEGIN
c.Handle^ (f, m);
WITH f: DialogFrames.Frame DO
WITH m: Oberon.InputMsg DO
IF m.id = Oberon.track THEN c.Track (m.X, m.Y, m.keys, f, f.panel) END
| m: NotifyMsg DO
c.Hide; c.Restore
ELSE
END
ELSE
END
END Handle;
PROCEDURE Clock;
VAR msg: NotifyMsg;
BEGIN
IF Oberon.Time () >= wakeUp THEN
Oberon.GetClock (msg.new.timeStamp, msg.new.dateStamp);
IF msg.new.dateStamp # old.dateStamp THEN
wakeUp := Oberon.Time () + ticks * 15 DIV 16;
Viewers.Broadcast (msg); old := msg.new
ELSE
wakeUp := Oberon.Time () + ticks DIV 16
END
END
END Clock;
PROCEDURE Insert*;
(** Insert ([name] [x y w h] | ^ ) inserts a date - item in the panel containing the caret position *)
VAR x, y, x1, y1, w, h: INTEGER; b: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR;
BEGIN
NEW (b);
DialogFrames.GetCaretPosition (p, x, y);
IF (p # NIL) THEN
b.Init; In.Open; In.Name (name);
IF ~In.Done THEN COPY ("", name); In.Open END;
b.SetName (name);
In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H
ELSE
IF w < 0 THEN w := W END;
IF h < 0 THEN h := H END
END;
b.SetDim (x1, y1, w, h, FALSE); p.Insert (b, FALSE)
ELSE
Dialogs.res := Dialogs.noPanelSelected
END;
IF Dialogs.res # 0 THEN Dialogs.Error ("DialogDates") END;
END Insert;
BEGIN
Oberon.GetClock (old.timeStamp, old.dateStamp); fnt := Fonts.This ("Syntax10.Scn.Fnt");
NEW (Task); Task.safe := FALSE; Task.handle := Clock; Oberon.Install (Task);
month := "JanFebMarAprMayJunJulAugSepOctNovDec"
END DialogDates.